package com.yidu.qianfeng.service.impl;

import com.yidu.qianfeng.common.bean.finance.FinanceCondition;
import com.yidu.qianfeng.common.bean.finance.Spend;
import com.yidu.qianfeng.common.util.JsonMsgUtil;
import com.yidu.qianfeng.common.util.LayuiJsonWrap;
import com.yidu.qianfeng.mapper.SpendMapper;
import com.yidu.qianfeng.service.SpendServiceInter;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("spendServiceImpl")
public class SpendServiceImpl implements SpendServiceInter {
    @Resource(name = "spendMapper")
    private SpendMapper mapper;

    @Override
    public String insertSpend(Spend spend) {
        int insert = mapper.insert(spend);
        return JsonMsgUtil.createJsonMessage(insert, "新增成功", "新增失败");
    }

    @Override
    public List<Spend> selectAllSpend(int page, int limit) {
        List<Spend> spends = mapper.selectAllSpend(page, limit);
        return spends;
    }

    @Override
    public int selectSpendCount() {
        return mapper.selectSpendCount();
    }

    @Override
    public LayuiJsonWrap selectSpendByCondition(FinanceCondition condition) {
        condition.setOffset((condition.getPage()-1)*condition.getCount());
        condition.setFinanceVoucherNum("%"+condition.getFinanceVoucherNum()+"%");
        return new LayuiJsonWrap(condition.getCount(),mapper.selectSpendByCondition(condition));
    }
}
